function lookupdate_order(id) {
    $.getJSON("/document/lookbyid","id="+id,function (dataA) {
        var img = dataA.type;
        if (img == 1) {
            img = "<img src='../images/document/jia2.png'>";
        } else if (img == 2) {
            img = "<img src='../images/document/doc.png'>";
        } else if (img == 3) {
            img = "<img src='../images/document/txt.png'>";
        }else if (img == 4) {
            img = "<img src='../images/document/jpg.png'>";
        }else if (img == 5) {
            img = "<img src='../images/document/pdf.png'>";
        }else if (img == 6) {
            img = "<img src='../images/document/xls.png'>";
        }else if (img == 7) {
            img = "<img src='../images/document/zip.png'>";
        }

        let date = new Date(dataA.createDate);
        var m = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
        var d = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate())
        layer.open({
            type: 1,
            area: ['340px', '340px'],
            btnAlign:"c",
            content: ' <div id="box"><div id="main"><table border="0"><th style="width: 120px; text-align: right;">名称：</th><td><input style="text-align: center; margin-top: 5px;color: darkgray;" type="text" class="layui-input ctitle" placeholder="'+dataA.title+'" value=""/></td><tr><th style="text-align: right;height: 50px">类型：</th><td style="text-align: center;">'+img+'</td></tr><tr><th style="height:30px; text-align: right;">所在部门：</th><td style="text-align: center;">'+dataA.department.departmentname+'</td></tr><tr><th style="height:50px; text-align: right;">创建时间：</th><td style="text-align: center;">'+date.getFullYear()+"-"+m+"-"+d+'</td></tr></table></div>',
            btn: ["保存", "关闭"],
            btn1:function () {
                let title = $(".ctitle").val();
                let id = dataA.id;
                console.log("按钮中id的值++++++++++++++++"+id);
                console.log("按钮中title的值**************"+title);
                if (title == ""|title == null) {
                    layer.tips('所填内容不能为空！', '.ctitle');
                    return;
                }
                let json ={
                    title:title,
                    id:id
                }
                $.ajaxSettings.async = false;
                $.post("/document/updatebyid",json,function (data) {
                        if (data>0){
                            layer.alert('修改数据成功！', {
                                skin: 'layui-layer-lan'
                                , closeBtn: 0
                                , anim: 3 //动画类型
                            });
                            location.reload();
                    }else {
                        layer.tips('修改数据失败！', '.ctitle');
                    }
                })
                $.ajaxSettings.async = true;
            }
        });
    })
};

function reupdate(id) {
    console.log("reupdate传过来的id-------------------------"+id);
    layer.confirm('确定要删除吗？',
        {btn: ['删除','取消'],
            yes:function () {
                $.ajaxSettings.async = false;
                $.post("/document/reupdate","id="+id,function (data) {
                    if (data>0){
                        layer.alert('删除数据成功！', {
                            skin: 'layui-layer-lan'
                            , closeBtn: 0
                            , anim: 3 //动画类型
                        });
                        filelook($(".pid").val())
                    }else {
                        layer.alert('删除数据失败！', {
                            skin: 'layui-layer-lan'
                            , closeBtn: 0
                            , anim: 3 //动画类型
                        });
                        location.reload();
                    }
                })
                $.ajaxSettings.async = true;
            }
        })


}
function orderby(id) {
    console.log("orderby中的id=================================="+id);
    location.href="/document/orderby?id="+id;
}

function backcate() {
  location.href="/document/listdocument";
}
function addfolder() {
   var aid = $(".aid").val();
    $.getJSON("/document/lookbyid", "id=" + aid, function (dataB) {
        layer.open({
            type: 1,
            area: ['370px', '235px'],
            btnAlign: "c",
            shadeClose: true, //点击遮罩关闭
            content: ' <div id="box"><div id="main"><table border="0"><th style="width: 120px; text-align: right;">名称：</th><td><input style="text-align: center; margin-top: 5px;color: darkgray;" type="text" class="layui-input name" value=""/></td><tr><tr><th style="height:40px; text-align: right;">所在位置：</th><td class="path">' + dataB.path + '</td></tr></table></div>',
            btn: ["保存", "关闭"],
            btn1: function () {
                var name = $(".name").val();
                let parentId = dataB.parentId;
                let dp_id = dataB.dp_id;
                let path = $(".path").text();
                if (name == "" | name == null) {
                    layer.tips('所填内容不能为空！', '.name');
                    return;
                }
                $.getJSON("/document/repeatName", "title=" + name, function (dataD) {
                    if (dataD) {
                        layer.tips('列表已有相同文件名！请更换', '.name');
                        return;
                    } else {
                        let json = {
                            title: name,
                            parentId: parentId,
                            dp_id: dp_id,
                            path, path
                        }

                        $.ajaxSettings.async = false;
                        $.post("/document/addfile", json, function (dataC) {
                            if (dataC > 0) {
                                layer.alert('添加文件夹成功！', {
                                    skin: 'layui-layer-lan'
                                    , closeBtn: 0
                                    , anim: 3 //动画类型
                                });
                                filelook(parentId)
                            } else {
                                layer.alert('添加文件夹失败！', {
                                    skin: 'layui-layer-lan'
                                    , closeBtn: 0
                                    , anim: 3 //动画类型
                                });
                                filelook(parentId)
                            }
                        })
                        $.ajaxSettings.async = true;
                    }

                })
            }
        });
    })

}
function addfiles() {
    let id = $(".aid").val();
    console.log(id+"-------------------")
    layer.open({
        content:'/document/tofiles?id='+id,
        type:2,
        area: ['340px', '340px'],
        btnAlign: "c",
        btn: ["关闭"],
        btn1:function () {
            location.reload();
        }
    })
}

function filelook(ida) {
    let id = $(".pid").val();
    $('.table-page tr:gt(2)').remove();
    //$(".table-page tr:gt(1) td").html("&nbsp;")
    $.ajaxSettings.async = false;
    let json ={
        title:$(".tfile").val(),
        id:ida
    }
    $.getJSON("/document/orderby2",json,function (dataA) {
          console.log("传到js中数据----------------------------"+dataA);
           console.log("filelook传过来的id-------------------------"+id);
        if (dataA =="") {
            alert("没有查到该数据！", "", function () {
                //after click the confirm button, will run this callback function
            }, {type: 'question', confirmButtonText: 'OK'});
        }
        $(dataA).each(function (i,v) {
            console.log("文件类型============================="+v.type)
            var eid = v.id;
            var img = v.type;
            if (img == 1) {
                img = "<img src='../images/document/jia2.png'>";
            } else if (img == 2) {
                img = "<img src='../images/document/doc.png'>";
            } else if (img == 3) {
                img = "<img src='../images/document/txt.png'>";
            }else if (img == 4) {
                img = "<img src='../images/document/jpg.png'>";
            }else if (img == 5) {
                img = "<img src='../images/document/pdf.png'>";
            }else if (img == 6) {
                img = "<img src='../images/document/xls.png'>";
            }else if (img == 7) {
                img = "<img src='../images/document/zip.png'>";
            }
            let date = new Date(v.createDate);
            var m = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
            var d = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate())
            if (v.type != 1){
                var btn = "<input type=\"button\" style=\"height: 30px;line-height: 30px;\" class=\"layui-btn layui-btn-normal\" onclick='down(\""+v.newfilename+ "\")' value=\"下载\"> ";
                var check = "<button style=\"height: 30px;line-height: 30px;\" class=\"layui-btn\" onclick='che(\"" +v.path +"\")'>查看</button>";
                var title = "<p>" + v.title + "</p>";
            }else {
                btn = "";
                check = "";
                var title = "<p onclick='orderby(" + v.id + ")'>" + v.title + "</p>";
            }
            $(".maininfo").append("<tr style=\"height: 55px\">\n" +
                "      <td align=\"center\">"+(i+1)+"</td>"+
                "       <td colspan=\"2\" class=\"place\">"+title+"</p></td>\n" +
                "      <td align=\"center\">"+img+"</td>\n" +
                "       <td colspan=\"1\" class=\"place screenwriter\">"+v.department.departmentname+"</td>\n" +
                "       <td colspan=\"2\" class=\"place screenwriter\">"+date.getFullYear()+"-"+m+"-"+d+"</td>\n" +
                "       <td colspan=\"2\" class=\"place\"><input type=\"button\" style=\"height: 30px;line-height: 30px;\" class=\"layui-btn layui-btn-normal\" onclick='lookupdate_order("+v.id+")' value=\"修改\">    <input type=\"button\" style=\"height: 30px;line-height: 30px;\" class=\"layui-btn layui-btn-danger\" onclick='reupdate("+v.id+")' value=\"删除\">\n" +
                "       <span style=\"margin-left: 10px\">"+btn+"</span>"+
                "       <span style=\"margin-left: 10px\">"+check+"</span>"+
                "</td>\n" +
                "    </tr>");

        })
    })
    $.ajaxSettings.async = true;


}

function down(title) {
    console.log("新名字是--------------------------------------------"+title);
    location.href = "/document/download?title=" + title;
}
function che(path){
    location.href="http://"+path;
}

$(function(){
    //$('table tr:not(:first)').remove();
    var len = $('table tr').length;
    for(var i = 2;i<len;i++){
        var num =$('table tr:eq('+i+') td:first').text(i-1-1);
    }

});